// order//order/tuikuan/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInput: '',
    money: 0,
    oid: 0,
    list: [
      { id: 1, text: '计划有变，没时间消费', isSelected: 0 },
      { id: 2, text: '店里活动更优惠', isSelected: 0 },
      { id: 3, text: '预约不上', isSelected: 0 },
      { id: 4, text: '商家营业但不接待', isSelected: 0 },
      { id: 5, text: '商家停业/装修/转让', isSelected: 0 },
      { id: 6, text: '去过了，不太满意', isSelected: 0 },
      { id: 7, text: '网友评价不好', isSelected: 0 },
      { id: 8, text: '买多了/买错了', isSelected: 0 },
      { id: 9, text: '商家说可以直接团购价到店消费', isSelected: 0 },
      { id: 10, text: '后悔了，不想要了', isSelected: 0 },
      { id: 11, text: '联系不上商家', isSelected: 0 }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      money: options.money,
      oid: options.oid
    })
  },
  bindUser: function (e) {
    this.setData({
      userInput: e.detail.value
    })
  },
  selectReason: function (e) {
    let list = this.data.list;
    let id = e.currentTarget.dataset.id;
    for (let i = 0; i < list.length; i++) {
      if (list[i].id == id) {
        if (list[i].isSelected == 0) {
          list[i].isSelected = 1;
        } else {
          list[i].isSelected = 0;
        }
      }
    }
    this.setData({
      list: list
    })
  },
  tuikuan: function () {
    let that = this;
    let list = that.data.list;
    let applyReason = '';
    for (let i = 0; i < list.length; i++) {
      if (list[i].isSelected == 1) {
        applyReason += list[i].text + ',';
      }
    }
    if (that.data.userInput) {
      applyReason += that.data.userInput;
    }
    if (applyReason == '') {
      wx.showToast({
        title: '请选择退款原因',
        duration: 500
      })
      return;
    }
    wx.request({
      url: app.globalData.host + '/api/OrderAfter/ApplyOffLineRefund',
      data: {
        oid: that.data.oid,
        uid: app.globalData.userInfo.Uid,
        type: 0,
        applyReason: applyReason
      },
      method: 'POST',
      success: function (res) {
        if (res.data.Code == 0) {
          wx.showToast({
            title: '申请成功',
            duration: 500
          })
          wx.reLaunch({
            url: '/merchant/merchants/myCardCoupon/index?tagindex=4',
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  }

})